package pl.edu.agh.persdoc.model;

public class ViewResultParser {

	private static final String ID_TAG="_id";
	private static final String REV_TAG="_rev";
	private static final String SCHEDULE="schedule";
	
    public static String getIdFromRecord(String record){
     
    	final int indexOfIdTag=record.indexOf(ID_TAG);
    	final int indexOfRevTag=record.indexOf(REV_TAG);	
    	int idStartIndex=indexOfIdTag+ID_TAG.length();
    	int idEndIndex=indexOfRevTag-1;
    	String id=record.substring(idStartIndex,idEndIndex);
    	return clearString(id);
    	
    }
    
    public static String getScheduleFromRecord(String record){
        
     	int scheduleTagIndex=record.indexOf(SCHEDULE);
     	int scheduleStartIndex=scheduleTagIndex+11;
    	int scheduleEndIndex=record.length()-2;
    	return clearString(record.substring(scheduleStartIndex,scheduleEndIndex));
    	
    }
    
    private static String clearString(String str){
    	
    	return str.trim().replaceAll("\\\\", "");
    	
    }
	
	
}
